<%@page import="org.jfree.data.general.DefaultPieDataset"%>
<%@page import="org.jfree.chart.JFreeChart"%>
<%@page import="org.jfree.chart.ChartFactory"%>
<%@page import="org.jfree.chart.ChartUtilities"%>
<%@page import="java.io.File"%>
<%@page import="java.io.IOException"%>
<%@page import="memory.JvmInformation"%>
<%@page import="java.text.DecimalFormat"%>
<html>
<head>
</head>
<body>
<%
  JvmInformation jvmobj = (JvmInformation)request.getAttribute("jvmobj");
  long max = jvmobj.getUsedMaxHeapMemo();
  float used  = jvmobj.getUsedHeapMemo();
  float per = (used/max ) * 100;
  DecimalFormat df = new DecimalFormat("0.00");
  
  DefaultPieDataset pds = new DefaultPieDataset();  
  pds.setValue("used memory "+ df.format(per) + " %", jvmobj.getUsedHeapMemo());
  pds.setValue("free memory "+df.format(100-per)+" %", jvmobj.getUsedMaxHeapMemo());
  JFreeChart jfc = ChartFactory.createPieChart("Memory use", pds, true, true, true);
  try{
	 ChartUtilities.saveChartAsPNG(new File(request.getRealPath("") + "/tmp/chart.png" ), jfc, 500, 300);	
  }catch(IOException e){
	 e.printStackTrace();
  }
  
%>

<img src="<%= request.getContextPath() + "/tmp/chart.png" %>">
</body>
</html>
